/**
 * @Date 2025/1/8 9:20
 * @Created by 衡盛永
 */

package org.example.deploy.security;

//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.web.authentication.AuthenticationFailureHandler;
//import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginFilter
//        extends UsernamePasswordAuthenticationFilter
{
    // 自定义认证成功处理器
//    private AuthenticationSuccessHandler successHandler;
//
//    // 自定义认证失败处理器
//    private AuthenticationFailureHandler failureHandler;
//
//    public LoginFilter(AuthenticationSuccessHandler successHandler, AuthenticationFailureHandler failureHandler) {
//        this.successHandler = successHandler;
//        this.failureHandler = failureHandler;
//        // 可以在这里设置登录 URL，例如："/api/login"
//        setFilterProcessesUrl("/api/login");
//    }
//
//    @Override
//    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) {
//        // 自定义请求参数字段名（如果不是默认的 username 和 password）
//        String username = obtainUsername(request);  // 获取用户名
//        String password = obtainPassword(request);  // 获取密码
//
//        // 创建用户名和密码的认证令牌
//        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
//
//        // 设置认证请求的详细信息（例如：客户端的IP、请求参数等）
//        setDetails(request, authenticationToken);
//
//        // 返回认证令牌，Spring Security 会进行认证
//        return this.getAuthenticationManager().authenticate(authenticationToken);
//    }
//
//    @Override
//    protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException {
//        // 认证成功后的处理，例如返回一个 JWT Token
////        successHandler.onAuthenticationSuccess(request, response, authResult);
//    }
//
//    @Override
//    protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException, ServletException {
//        // 认证失败后的处理，例如返回一个错误消息
////        failureHandler.onAuthenticationFailure(request, response, failed);
//    }
}
